<?php if (!defined('THINK_PATH')) exit(); require_once "./sample/php/jssdk.php"; $jssdk = new JSSDK("wx73f8f21829bef9c6", "00ea7e3072f302d457e88b7402dc6429"); $signPackage = $jssdk->GetSignPackage(); ?>
<!DOCTYPE html>
<html>
	<head> 
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
		<title><?php echo C('WEB_SITE_TITLE');?></title>
		<link rel="stylesheet" href="/Public/Home/css/swiper-3.3.1.min.css">
		<script src="/Public/Home/js/swiper-3.3.1.min.js"></script>
		<link rel="stylesheet" href="/Public/Home/css/common.css?41511">
		<link rel="stylesheet" href="/Public/Home/css/main.css?4545145">
		<script src="/Public/Home/js/zepto.js"></script>
		<script src="/Public/Home/js/common.js"></script>
		<script src="/Public/Home/js/iscroll-probe.js"></script>
		<script src="/Public/Home/js/delIOS_huitan.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	</head>
	<body style="background: #f5f5f5;" class="box">
		<!--提示文字-->
		<div class="tip" style="opacity: 0;z-index: -1"></div>
		<!--正文区域-->
		<div id="detailShareMain" class="fastscroll">
			<div class="contain maxWidth">
				<!-- 顶部-->
				<div class="top clear">
					<img src="/Public/Home/img/sharePindanDetail/top.jpg" alt=""/>
					<a class="back" href="/"><span class="hz">&#xe600;</span><i>返回首页</i></a>
					<?php if($spell['state'] < 3): ?><a href="<?php echo U('Spell/detail',array('id'=>$spell['id']));?>" class="btn">去开团</a><?php endif; ?>
				</div>
				
				<!-- 商品信息-->
				<div class="proinofo">
					<img src="<?php echo ($share_img); ?>" alt=""/>
					<div class="right">
						<p class="name"><?php echo ($spell["title"]); ?></p>
						<p class="num"><?php echo ($spell["num"]); ?>人团</p>
						<p class="price">
							<span class="red">&yen;<span class="money"><?php echo ($spell["price"]); ?></span></span>
							<span class="text">拼团可省<span class="money"><?php echo ($spell['oldprice']-$spell['price']); ?></span>元</span>
						</p>
					</div>
				</div>
				<!-- 头像区域-->
				<?php if($spell['state'] < 3): ?><div class="headimgs">
					<!-- wen.jpg 这个是?的图片 -->
					<?php $__FOR_START_13432__=0;$__FOR_END_13432__=$spell['num'];for($i=$__FOR_START_13432__;$i < $__FOR_END_13432__;$i+=1){ ?><div>
						<?php if($team != '' and $users[$i]['id'] == $team['user_id']): ?><img src="/Public/Home/img/sharePindanDetail/guan.png" alt="" class="guan"/><?php endif; ?>
						<?php if($users[$i] != null): ?><img src="<?php echo ((isset($users[$i]['image']) && ($users[$i]['image'] !== ""))?($users[$i]['image']):'/Public/Home/img/mytouxiang.png'); ?>" />
						<?php else: ?>
						<img src="/Public/Home/img/sharePindanDetail/wen.png" class="wen"/><?php endif; ?>
					</div><?php } ?>
					<!-- <div>
						<img src="/Public/Home/img/sharePindanDetail/guan.png" alt="" class="guan"/>
						<img src="/Public/Home/img/sharePindanDetail/headimg.jpg" alt=""/>
					</div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/headimg.jpg" alt=""/></div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div>
					<div><img src="../../../../../Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div>
					<div><img src="/Public/Home/img/sharePindanDetail/wen.png" alt="" class="wen" /></div> -->
				</div><?php endif; ?>
				<!-- 名额区域-->
				<div class="minge">
					<!--
						这个倒计时，肯定是开始的，所以只有距离结束的
						data-status="2"	这个可以写成死值 2
					-->
					<?php if($team["status"] == 0): ?><div class="line1">仅剩<span class="red"><?php echo ($num); ?></span>个名额</div>				
					<div class="line2">
						剩余
						<span class="daojishi" data-juEndTime="<?php echo date('Y/m/d H:i:s',$spell['end_date']);?>" data-status="<?php echo ($spell["state"]); ?>">
							<span class="shi com">88</span>:<span class="fen com">88</span>:<span class="com"><b class="miao">88</b>.<b class="span hmiao">8</b></span>
						</span>
						结束
					</div>
					<a href="javascript:;" class="enter">立即参团</a>
					<?php elseif($team["status"] == 2): ?>
					<div class="endState">
						<div class="line1">拼团已经结束了</div>
					</div>
					<?php else: ?>
					<!--拼团完成的状态-->
					<div class="endState">
						<div class="line1">拼团成功了，可以再开一团哦~</div>
						<a href="<?php echo U('Cart/step3',array('spell_id'=>$id));?>" class="zaikai">再开一团</a>
					</div><?php endif; ?>
				</div>
				<!-- 广告 750 300-->
				<a class="ad" href="<?php echo ($ads["link_url"]); ?>"><img src="<?php echo ($ads["image"]); ?>" alt=""/></a>
				<!-- 拼团须知-->
				<div class="pintuanXuzhi">
					<p class="tit">拼团须知</p>
					<ul class="clear">
						<li>· 邀请好友参团</li>
						<li>· 人满分别发货</li>
						<li>· 人不满将退款至余额</li>
					</ul>
				</div>
				<!-- 本期拼团推荐-->
				<div class="pintuanMiaosha">
					<p class="tit"><img src="/Public/Home/img/sharePindanDetail/pttj.png" /></p>
					<!--
						status1代表距离开始 status2代表距离结束
						liendTimeStr='2016-12-24 16:46:10';
						从后台读取的时间截止的毫秒数 1478350790050 传ms数或者，这种格式的字符串都行
					-->
					<ul class="lie">
						<?php if(is_array($spelllist)): $i = 0; $__LIST__ = $spelllist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><li data-juStartTime="<?php echo ($v["start_date"]); ?>" data-juEndTime="<?php echo ($v["end_date"]); ?>" data-status="<?php echo ($v["state"]); ?>">
							<a href="<?php echo U('Spell/detail',array('id'=>$v['id']));?>">
								<!-- 700 400-->
								<div class="imgp">
									<img src="<?php echo ($v["image"]); ?>"/>
								</div>
								<div class="line1">
									<span class="share"><?php echo ($statearr[$v['state']]); ?></span>
									<?php if($v['state'] < 3): ?><span class="daojishi"><span class="daojishiText">距结束</span> <span class="time"><b class="shi">08</b>:<b class="fen">26</b>:<b class="miao">58</b></span></span><?php endif; ?>
								</div>
								<div class="line2"><?php echo ($v["title"]); ?></div>
								<div class="line3">
									<span class="xian">&yen;<span class="money"><?php echo ($v["price"]); ?></span></span>
									<del>&yen;<span class="money"><?php echo ($v["oldprice"]); ?></span></del>
								</div>
								<div class="line4 textR">
									<span class="goKaituan">
										<?php echo ($v["num"]); ?>人团<span class="line"></span>去开团
									</span>
								</div>
							</a>
						</li><?php endforeach; endif; else: echo "" ;endif; ?>
					</ul>
					<div class="more">
						<a href="<?php echo U('Spell/index');?>">查看更多 <span class="hz">&#xe60c;</span></a>
					</div>
				</div>
			</div>
		</div>

		<script>
			//点击top返回按钮
			$('.topBackTitle .back').on('click',function(){
				location.href='';
			});

			//money显示.00/////////////////////////////////////////////////////////////////////////////////////
			moneyZero2();
			function moneyZero2(){
				CashToZero2('#detailShareMain .money');
			}

			//拼团倒计时///////////////////////////////////////////////////////////////////////////////////////////
			//本期拼团推荐倒计时
			//距离结束 距离开始 公共调用的函数
			function setPTtime(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				var NowTime = new Date();
				var t =licurrTime.getTime() - NowTime.getTime();
				var d=0;
				var h=0;
				var m=0;
				var s=0;
				if(t>=0){
					d=Math.floor(t/1000/60/60/24);
					h=Math.floor(t/1000/60/60%24);
					m=Math.floor(t/1000/60%60);
					s=Math.floor(t/1000%60);
				}else{
					clearInterval(litimer);
					//距离开始倒计时结束后，直接走距离结束的倒计时
					if(listatus==1){
						listatus=2;
						juliEndTimer(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
						//ajax 把后台的status设置为2
						$.ajax({
							type: 'GET',
							url: "<?php echo U('Spell/updateSpell');?>",
							dataType: 'json',
							success: function(data){

							},
							error: function(xhr, type){
								console.log('Ajax error!');
							}
						});
					}
				}

				//天转换成小时
				h+=d*24;
				$(li).find('.line1 .daojishi .time .shi').text(zhuanTwo(h));
				$(li).find('.line1 .daojishi .time .fen').text(zhuanTwo(m));
				$(li).find('.line1 .daojishi .time .miao').text(zhuanTwo(s));
			}
			function zhuanTwo(v){
				//时分秒转成两位数
				if(v<10){
					return '0'+v;
				}else{
					return ''+v;
				}
			}
			//距离结束
			function juliEndTimer(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				var liEndTime= new Date(liendTimeStr);
				licurrTime=liEndTime;
				$(li).find('.daojishiText').text('距离结束');
				litimer=setInterval(function(){
					setPTtime(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
				},30);
			}
			//距离开始
			function juliStartTimer(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				var liStartTime= new Date(listartTimeStr);
				licurrTime=liStartTime;
				$(li).find('.daojishiText').text('距离开始');
				litimer=setInterval(function(){
					setPTtime(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
				},30);
			}
			//根据status走不同的定时器
			function setliDaojishi(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				if(listatus==1){
					juliStartTimer(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
				}else if(listatus==2){
					juliEndTimer(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
				}
			}
			//获取所有的li，执行倒计时操作
			var allli=$('#detailShareMain .pintuanMiaosha .lie li');
			for(var x=0;x<allli.length;x++){
				//设置
				allli[x].timer=null;
				allli[x].currTime=null;

				//获取
				var li=$(allli[x]);
				var listatus=$(allli[x]).attr('data-status');
				var listartTimeStr=$(allli[x]).attr('data-juStartTime');
				var liendTimeStr=$(allli[x]).attr('data-juEndTime');
				var licurrTime=allli[x].currTime;
				var litimer=allli[x].timer;

				//执行倒计时操作
				setliDaojishi(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
			}

			//当前拼团倒计时//////////////////////////////////////////////////////////////////
			setCurrDaojishi();
			function setCurrDaojishi(){
				var obj=$('#detailShareMain .minge .line2 .daojishi');
				var status=obj.attr('data-status');
				var endTimeStr=obj.attr('data-juEndTime');
				var currTime=obj[0].currTime;
				var timer=obj[0].timer;

				juliEndTimer1(obj,status,null,endTimeStr,currTime,timer);
			}
			//距离结束
			function juliEndTimer1(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				var liEndTime= new Date(liendTimeStr);
				licurrTime=liEndTime;
				litimer=setInterval(function(){
					setPTtime1(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
				},30);
			}
			function setPTtime1(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer){
				var NowTime = new Date();
				var t =licurrTime.getTime() - NowTime.getTime();
				var d=0;
				var h=0;
				var m=0;
				var s=0;
				var ms=0;
				if(t>=0){
					d=Math.floor(t/1000/60/60/24);
					h=Math.floor(t/1000/60/60%24);
					m=Math.floor(t/1000/60%60);
					s=Math.floor(t/1000%60);
					ms = Math.floor(t%1000);
					ms=ms.toString().substr(0,1);
					
					h=d*24+h;
				}else{
					clearInterval(litimer);
					//距离开始倒计时结束后，直接走距离结束的倒计时
					if(listatus==1){
						listatus=2;
						juliEndTimer1(li,listatus,listartTimeStr,liendTimeStr,licurrTime,litimer);
						//ajax 把后台的status设置为2
						$.ajax({
							type: 'GET',
							url: "<?php echo U('Spell/updateSpell');?>",
							dataType: 'json',
							success: function(data){

							},
							error: function(xhr, type){
								console.log('Ajax error!');
							}
						});
					}
				}

				$('#detailShareMain .minge .line2 .shi').text(zhuanTwo(h));
				$('#detailShareMain .minge .line2 .fen').text(zhuanTwo(m));
				$('#detailShareMain .minge .line2 .miao').text(zhuanTwo(s));
				$('#detailShareMain .minge .line2 .hmiao').text(ms);
			}

			/* //点击去开团
			$('#detailShareMain .top .btn').on('click',function(){
				console.log('点击去开团');
			}); */
			//点击 立即参团
			$('#detailShareMain .minge .enter').on('click',function(){
				var user_id = "<?php echo ($user_id); ?>";
				if(user_id==""){
					location.href = "<?php echo U('/Member/Login/index');?>";
				}
				var team_id = "<?php echo ($team_id); ?>";
				$.ajax({
					type: 'GET',
					url: "<?php echo U('Spell/teamIsFull');?>",
					dataType: 'json',
					data:{team_id:team_id},
					success: function(data){
						//console.log(data);
						if(data.status<1){
							tipFun(data.info);
							return;
						}else{
							if(user_id==""){
								location.href = "<?php echo U('/Member/Login/index');?>";
							}else{
								location.href = "<?php echo U('Cart/step3');?>&team_id=<?php echo ($team_id); ?>&spell_id=<?php echo ($id); ?>";
							}
						}
					},
					error: function(xhr, type){
						console.log('Ajax error!');
					}
				});
				//console.log('立即参团');
			});

			//tip
			function tipFun(str){
				$('.tip').text(str).css({
					'opacity':'1',
					'z-index':'9999'
				});
				setTimeout(function(){
					$('.tip').css('opacity','0');
					setTimeout(function(){
						$('.tip').css('z-index','-1');
					},300);
				},1300);
			}
			
			wx.ready(function(){
				var weiurl = "<?php echo ($weiurl); ?>";
				var weilink = window.location.href;
				var weititle = "<?php echo ($spell["title"]); ?>";
				var imgurl = "<?php echo C('WEBSITE'); echo ($share_img); ?>";
				var brief = "<?php echo ($share_desc); ?>";
				//console.log(weiurl);
		      wx.checkJsApi({
		          jsApiList: ['onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
		      });
		       wx.onMenuShareTimeline({
		          title: weititle, 
		          link: weiurl,
		          desc: brief,
		          imgUrl: imgurl, // 分享图标
		          trigger:function(res){
		          },
		          success: function () {
		              //alert('已分享');
		          },
		          cancel: function () {
		          },
		          fail:function(){
		          } 
		      });
		      wx.onMenuShareAppMessage({
		          title: weititle, // 分享标题
		          desc: brief, // 分享描述
		          link: weiurl, // 分享链接
		          imgUrl: imgurl, // 分享图标
		          type: 'link', // 分享类型,music、video或link，不填默认为link
		          dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
		          success: function () {
		            //  alert('hello');
		          },
		          cancel: function () {
		          }
		      });
		       //分享到QQ
		      wx.onMenuShareQQ({
		          title: weititle,
		          desc: brief,
		          link: weiurl,
		          imgUrl: imgurl, // 分享图标
		          success: function () { 
		             // 用户确认分享后执行的回调函数
		          },
		          cancel: function () { 
		             // 用户取消分享后执行的回调函数
		          }
		      });
		      //分享到腾讯微博
		      wx.onMenuShareWeibo({
		          title: weititle,
		          desc: brief,
		          link: weiurl,
		          imgUrl: imgurl, // 分享图标
		          success: function () { 
		             // 用户确认分享后执行的回调函数
		          },
		          cancel: function () { 
		              // 用户取消分享后执行的回调函数
		          }
		      });
		
		      // 分享到qq空间
		      wx.onMenuShareQZone({
				    title: weititle, // 分享标题
				    desc: brief, // 分享描述
				    link: weiurl, // 分享链接
				    imgUrl: imgurl, // 分享图标
				    success: function () { 
				       // 用户确认分享后执行的回调函数
				    },
				    cancel: function () { 
				        // 用户取消分享后执行的回调函数
				    }
				});
			});
			
		</script>
	</body>
</html>